# -*- coding: utf-8 -*-
import scrapy
import json
from Douyu.items import DouyuItem

class DouyuSpider(scrapy.Spider):
    name = 'douyu'
    allowed_domains = ['douyu.com']
    basr_url = 'http://capi.douyucdn.cn/api/v1/getVerticalRoom?limit=20&offset={}'
    page = 0
    start_urls = [basr_url.format(page)]


    def parse(self, response):
        data_list = json.loads(response.body.decode())['data']

        for a in data_list:
            item = DouyuItem()
            # 昵称
            item['nickname'] = a['nickname']
            # 图片地址
            item['vertical_src'] = a['vertical_src']

            yield item